
var RiskComm = function(){

    // 声明返回对象
    var base = {};

    function local_path(){
        return $('#JQ_local_path').attr('content');
    };

    function gis_path(){
        return $('#JQ_gis_path').attr('content');
    };

    /**
     * 加载 下拉框标签
     */
    function loadSelectTag(obj) {

        var _tagId = obj.tagId;
        var _path = obj.path;
        var _msg = obj.msg;

        $.post(_path,
            function (data) {
                var _data = $.parseJSON(data);
                var _result = _data.result;
                var _html = "<li ><a href='javascript:void(0);'>" + _msg + "</a></li>";
                $.each(_result, function () {
                    _html += "<li ><a href='javascript:void(0);' id='" + this.id + "'>" + this.name + "</a></li>";
                });
                $("#"+_tagId).html(_html);
            }
        );
    }

    /**
     * 加载评价时间
     */
    function loadEvaluateDate(obj) {

        var _evaluateDateArr = obj.evaluateDateArr;
        $.post(RiskComm.local_path()+"/riskMgr/comm/queryYears.json",
            function (data) {
                var _data = $.parseJSON(data);
                var _result = _data.result;
                var _html = "";
                $.each(_result, function () {
                    _html += "<li ><a href='javascript:void(0);' id='" + this.name + "'>" + this.name + "</a></li>";
                });
                $("#"+_evaluateDateArr).html(_html);
            }
        );
    }

    /**
     * 加载管道信息
     */
    function loadPipeLine(obj) {

        var _pipeLineArr = obj.pipeLineArr;
        var _pipeSegmentSearch = obj.pipeSegmentSearch;
        var _pipeSegmentArr = obj.pipeSegmentArr;

        $.post(RiskComm.local_path()+"/comm/getLine.json",
            function (data) {
                var _data = $.parseJSON(data);
                var _result = _data.result;
                var _html = "<li><a href='javascript:void(0);' name='pipeLine'>所有管道</a></li>";
                $.each(_result, function () {
                    _html += "<li ><a href='javascript:void(0);' id='" + this.id + "' name='pipeLine'>" + this.name + "</a></li>";
                });
                $("#"+_pipeLineArr).html(_html);

                // 绑定事件
                $("a[name$='pipeLine']").live('click', function () {
                    var _id = $(this).attr("id");
                    queryPipeSegment({dataLineId:_id, pipeSegmentSearch:_pipeSegmentSearch, pipeSegmentArr:_pipeSegmentArr});
                });
            }
        );
    }

    /**
     * 查询管段信息
     *
     * @param lineId
     */
    function queryPipeSegment(obj) {

        var _lineId = obj.dataLineId;
        var _pipeSegmentSearch = obj.pipeSegmentSearch;
        var _pipeSegmentArr = obj.pipeSegmentArr;

        $("#"+_pipeSegmentSearch).html("<a href='javascript:void(0);'>管段名称</a>");

        $.post(RiskComm.local_path()+"/comm/getSegment.json",
            {"lineId": _lineId},
            function (data) {
                var _data = $.parseJSON(data);
                var _result = _data.result;
                var _html = "<li><a href='javascript:void(0);'>全部管段</a></li>";
                if (_result.length > 0) {
                    $.each(_result, function (i, evalue) {
                        _html += '<li ><a href="javascript:void(0);" id="' + evalue.ID + '">' + evalue.NAME + '</a></li>';
                    });
                    $("#"+_pipeSegmentSearch).html("<a href='javascript:void(0);'>全部管段</a>");
                } else {
                    $("#"+_pipeSegmentSearch).html("<a href='javascript:void(0);'>管段名称</a>");
                }
                $("#"+_pipeSegmentArr).html(_html);
            }
        );
    }

    // 导出公共方法
    base.loadEvaluateDate = loadEvaluateDate;
    base.loadPipeLine = loadPipeLine;
    base.loadSelectTag = loadSelectTag;
    base.local_path = local_path;
    base.gis_path = gis_path;

    return base;
}()

